package galaxy;

public class GalaxyModel extends AbstractModel {

  public void init()
  {
    startDrawingFrom(random(0.4, 0.6), random(0.4, 0.6)).atAngle(degrees(random(0, 360)));
    startFrom("A");
    
    int A = random(2,8);
    int C = random(1,5);

    on("A").output(repeat("-[B]+", A));
    on("B").output("+[C]+[B]");
    on("C").output(repeat("+-[D]", C)+ "+[E]");
    on("D").output("-[E]");

    on("[").pushContext();
    on("]").popContext();

    on("+").rotate(degrees(A * random(10, 30)));
    on("-").rotate(degrees(C * random(5, 20)));
    
    on("A").explode().particles(random(100, 2000)).color(hsb(255, 0, 255)).disperse(random(0.5, 2)).speed(random(0.5, 1));

    on("B").go(random(110, 180)).explode().particles(400).color(hsb(255, 0, 255)).disperse(random(0.3, 0.6)).width(random(1.0, 3.0)).height(random(2.0, 4.0));
    on("C").go(random(80, 140)).explode().particles(300).color(hsb(random(0,255), 255, 255)).disperse(random(0.05, 0.2)).width(random(4.0, 6.0));
    on("D").go(random(50, 110)).explode().particles(200).color(hsb(random(0,255), 255, 255)).disperse(random(0.2, 0.4)).width(random(1.5, 3.5));
    on("E").go(random(30, 40)).explode().particles(50).color(hsb(255, 0, 255)).disperse(random(0.3, 0.7));
    
    rounds(random(15, 17));
  }
  
  public String repeat(String s, int times)
  {
	  String result = "";
	  while(times-- > 0) {
		  result += s;
	  }
	  return result;
  }
}
